// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        effectAsset: {
            default: null,
            type: cc.EffectAsset
        }
    },

    onLoad() {
        this._useRainEffect();
    },

    _useRainEffect() {
        let material = new cc.Material();
        material.initWithEffect(this.effectAsset);
        this._time = 0;

        this.node.getComponent(cc.Sprite).sharedMaterials[0] = material;
    },

    update(dt) {
        this._time += dt;
        let material = this.node.getComponent(cc.Sprite).sharedMaterials[0];
        material.setProperty('u_time', this._time);
    },
});
